/*
 * CAD System for seamlessly constructing 2D and 3D scenes with aspects and motion
 * Copyright (C) 2013 Bernhard Haumacher and others
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package de.haumacher.draw5d.math.d2.constructions;

import de.haumacher.draw5d.dataflow.Scope;
import de.haumacher.draw5d.dataflow.core.ScopeImpl;
import de.haumacher.draw5d.math.d2.D2;
import de.haumacher.draw5d.math.d2.D2Base;
import de.haumacher.draw5d.math.d2.Straight;
import de.haumacher.draw5d.math.d2.constructions.internal.MiddleImpl;
import de.haumacher.draw5d.math.d2.constructions.internal.ProjectionOnStraightImpl;
import de.haumacher.draw5d.math.d2.constructions.internal.StraightThroughPointsImpl;
import de.haumacher.draw5d.math.d2.internal.D2BaseImpl;
import de.haumacher.draw5d.math.d2.internal.D2Impl;
import de.haumacher.draw5d.math.values.Scalar;

public class Factory {

	public static D2Base d2Base() {
		return new D2BaseImpl();
	}
	
	public static D2 d2(Scope scope) {
		return new D2Impl(scope);
	}

	public static Middle middle(Scope scope) {
		return new MiddleImpl(scope);
	}

	public static Scope scope() {
		return new ScopeImpl();
	}

	public static Straight straight(Scope scope, D2 p1, D2 p2) {
		StraightThroughPointsImpl result = new StraightThroughPointsImpl(scope);
		result.set(StraightThroughPointsImpl.P1, p1);
		result.set(StraightThroughPointsImpl.P2, p2);
		return result.getResult();
	}

	public static D2 perpendicularPoint(Scope scope, Straight s, D2 p) {
		ProjectionOnStraightImpl projection = new ProjectionOnStraightImpl(scope);
		projection.set(ProjectionOnStraightImpl.STRAIGHT, s);
		projection.set(ProjectionOnStraightImpl.POINT, p);
		return projection.getResult();
	}

	public static Straight perpendicularStraight(Scope scope, Straight s, D2 p1) {
		D2 p2 = perpendicularPoint(scope, s, p1);
		return straight(scope, p1, p2);
	}

	public static Scalar length(Scope scope) {
		return new ScalarImpl(scope);
	}
}
